using System;

namespace Sedna.Core.Controller.Configurations
{
    public class CommandConfiguration : ClientScriptingConfiguration, ICommandConfiguration
	{
        private string onClick;
		private string commandName;
		private string jScriptCommandName;
        //Commented out because of problem with grid-generated CommandArgument(HSBC-158). You are welcome to introduce a better solution.
		private ICommandArgumentGenerator commandArgumentGenerator;// = EmptyStringCommandArgumentGenerator.Instance;
		private bool defaultOnEnter = false;


	    public string OnClick
	    {
	        get { return onClick; }
	        set { onClick = value; }
	    }

	    public string CommandName
		{
			get { return commandName; }
			set { commandName = value; }
		}


		public string JScriptCommandName
		{
			get { return jScriptCommandName; }
			set { jScriptCommandName = value; }
		}

		public ICommandArgumentGenerator CommandArgumentGenerator
		{
			get { return commandArgumentGenerator; }
			set { commandArgumentGenerator = value; }
		}

		public bool DefaultOnEnter
		{
			get { return defaultOnEnter; }
			set { defaultOnEnter = value; }
		}

		public class EmptyStringCommandArgumentGenerator : ICommandArgumentGenerator
		{
			internal readonly static ICommandArgumentGenerator Instance = new EmptyStringCommandArgumentGenerator();

			public string GenerateCommandArguments(ICommandConfiguration configuration, IExecutionContext executionContext)
			{
				return string.Empty;
			}
		}
	    
	    public override IConfiguration CreateFromTemplate()
	    {
            CommandConfiguration template = (CommandConfiguration)base.CreateFromTemplate();
            template.commandName = this.commandName;
            template.jScriptCommandName = this.jScriptCommandName;
            template.commandArgumentGenerator = this.commandArgumentGenerator;
            template.defaultOnEnter = this.defaultOnEnter;
	        return template;
	    }
	}
}
